Ext.define('Zm.view.line.Pointset',{
    alias:'widget.linepointset',
    extend:'Ext.grid.Panel',
    requires:[
        'Ext.grid.RowNumberer'
    ],
    initComponent:function(){
        var me = this,
            lang = Zm.i18n.Lang;
            
        me.lineid = 0;
        me.eid = -1;
        me.devs = null;
        me.linetype = 0;
        Ext.apply(me,{
            title: lang.tPointSet,
            layout:'fit',
            store:'Pointset',
            columns:[
                {xtype:'rownumberer',text:lang.tIndex,width:35},
                {text:lang.tPoint,dataIndex:'xyz',flex:1}
            ],
            viewConfig : {
                loadMask : false
            },
            dockedItems: [{
                xtype:'toolbar',
                dock:'top',
                items:[{
                    text:lang.tAddPoint,
                    iconCls:'lineadd',
                    disabled: true,
                    action:'add'
                },{
                    text:lang.tDel,
                    iconCls:'linedel',
                    disabled: true,
                    action:'del'
                },{
                    text:lang.tFinish,
                    iconCls:'lfinish',
                    disabled:true,
                    action:'finish'
                }]
            }],
            listeners:{
                selectionchange:me.onSelChange
            }
        });
        
        me.addEvents('propertychange');
        me.callParent(arguments);
        me.store.on('metachange',me.onMetaChange,me);
    },
    onSelChange: function(selModel, selections){
        var me = this,
            flag = selections.length === 0,
            btn2 = me.down('button[action=del]');
        btn2.setDisabled(flag);
    },
    setValue:function(lineid){
        var me = this,
            proxy = me.store.getProxy();
        me.lineid = lineid;
        proxy.extraParams = {lineid:lineid};
        me.store.load();
    },
    onMetaChange:function(store,meta,eOpts){
        var me = this,title='',
            lang = Zm.i18n.Lang,
            btn = me.down('button[action=add]');
        if(meta.hasline) {
            btn.setDisabled(false);
            me.devs = meta.devs;
            me.linetype = meta.linetype;
        }else{
            btn.setDisabled(true);
            me.devs = null;
        }
        if(meta.linename){
            title = Ext.String.format(lang.tPointTip,meta.linename);
        }
        me.setTitle(title);
    },
    editLid:function(lid){
        var me = this;
        me.eid = lid;
        me.down('button[action=finish]').setDisabled(false);
    },
    updatePoint:function(xyz){
        var me = this,
            record = me.store.findRecord('lid',me.eid);
        if(record){
            record.set('xyz',xyz);
        }
    }
});